﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Handrise.Mobile.BasicModal.Serialization;
using Handrise.Mobile.BasicModal.DataLayer;
using Handrise.Mobile.BasicModal.Audio;
using System.IO;
using Handrise.Mobile.BasicModal.Camera;

namespace Handrise.CDCable.Mobile.Business
{
    public class Class1
    {
        private AudioService audioService = new AudioService();
        private string fileName = "20101019160916.wav";

        public string Test()
        {
            //Line line = new Line();
            //line.LineID = "1";
            //line.LineName = "测试";
            //line.ParentID = "P1";
            //line.ParentNameParentID = "P1测试";
            //line.TestDateTime = DateTime.Now;
            //line.TestDateTime1 = null;
            //CompactFormatterPlus cfp = new CompactFormatterPlus();
            //byte[] tempdata = cfp.Serialize(line);
            //CDCalbeWebService.Service ws = new Handrise.CDCable.Mobile.Business.CDCalbeWebService.Service();
            //ws.HelloWorld(tempdata);
            return "";
        }

        public void TestDataLayer()
        {
            DataService dataService = new DataService();
            Plan task = new Plan();
            task.PlanID = Guid.NewGuid().ToString();
            task.Content = "任务内容" ;
            task.EndDateTime = DateTime.Now.AddDays(-1) ;
            task.StartDateTime = DateTime.Now.AddDays(1) ;
            task.Range = "任务范围123" ;
            task.State = "0" ;
            task.Title = "任务标题1";
            dataService.Add<Plan>(task);
        }

        public string TestBeginRecord()
        {
            if (audioService.PlayState != AudioState.Init)
            {
                return "播放正在进行中";
            }
            if (audioService.RecordState == AudioState.Init)
            {
                fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
                audioService.StartRecord(fileName);

                return "";

            }
            else
            {
                return "正在录音";
            }
        }

        public string TestEndBeginRecord()
        {
            if (audioService.RecordState == AudioState.Recording || audioService.RecordState == AudioState.RecordPause)
            {
                audioService.StopRecord();
                return "";
            }
            else
            {
                return "不能停止录音";
            }
        }

        public void TestPauseRecord()
        {
            audioService.PauseRecord();
        }

        public void TestRestartRecord()
        {
            audioService.ReStartRecord();
        }

        public void TestStartPaly()
        {
            audioService.StartPlay(fileName);
        }

        public void TestStopPlay()
        {
            audioService.StopPlay();
        }

        public void TestPausePlay()
        {
            audioService.PausePlay();

        }

        public void TestRestartPlay()
        {
            audioService.ReStartPlay();
        }

        public string  TestCamera()
        {
            CameraService cameraService = new CameraService();
            return cameraService.TakePicutes("Test1.jpg");
               
        }


    }
}
